<?php

/**
 * @var $this yii\web\View
 * @var $permissions array
 * @var $roles array
 */

use yak\layui\helper\RbacHelper;
use yak\layui\widgets\form\ActiveForm;
use yak\layui\widgets\form\AuthTree;

$this->title = '权限分配';

AuthTree::widget([
    'list' => $permissions,
    'dst' => '#LAY-auth-tree-permissions',
    'inputName' => 'permissions',
    'checkedId' => RbacHelper::permissionsByRole($name)
]);

AuthTree::widget([
    'list' => $roles,
    'dst' => '#LAY-auth-tree-roles',
    'inputName' => 'roles',
    'checkedId' => RbacHelper::rolesChild($name)
]);

$this->params['breadcrumbs'][] = ['url' => ['roles'], 'label' => '角色列表'];
$this->params['breadcrumbs'][] = $this->title;

?>

<div class="layui-card">
    <div class="layui-card-body">
        <?php $form = ActiveForm::begin([
            'method' => 'post',
            'options' => [
                'class' => 'layui-form'
            ]
        ]); ?>
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" value="<?= $name ?>" readonly/>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md5">
                <div class="layui-form-item form-block">
                    <label class="layui-form-label">选择角色</label>
                    <div class="layui-input-block">
                        <div id="LAY-auth-tree-roles"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6">
                <div class="layui-form-item form-block">
                    <label class="layui-form-label">选择权限</label>
                    <div class="layui-input-block">
                        <div id="LAY-auth-tree-permissions"></div>
                    </div>
                </div>
            </div>
        </div>
        <hr class="layui-bg-blue">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="submit" lay-submit lay-filter="LAY-auth-tree-submit">提交</button>
                <button class="layui-btn layui-btn-primary" type="reset">重置</button>
            </div>
        </div>
        <?php ActiveForm::end(); ?>
    </div>
</div>


